import { contextBridge, ipcRenderer } from 'electron'

contextBridge.exposeInMainWorld('electron', {
  restart: () => {
    ipcRenderer.invoke('restart')
  },
  async getApiPrefix() {
    const apiPrefix: string = await ipcRenderer.invoke('getApiPrefix')
    return apiPrefix
  },
  async getIpAddress() {
    const ip: string = await ipcRenderer.invoke('getIpAddress')
    return ip
  },
  async getServerPort() {
    const port: number = await ipcRenderer.invoke('getServerPort')
    return port
  },
  async getQuickInsertMockCode(codeFileName: string) {
    const mockCode: string = await ipcRenderer.invoke('getQuickInsertMockCode', codeFileName)
    return mockCode
  },
  newDocWin(flag: string, title: string, docFileName: string) {
    ipcRenderer.invoke('newDocWin', flag, title, docFileName)
  },
})
